﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace RoverStudio.Common.PositionSource
{
    public delegate void NewFrameDelegate(Bitmap frame);

    public interface IVideoSourceCommon
    {
        string Name { get; }
        bool IsActive { get; }

        event NewFrameDelegate NewFrame;
        
        /*
        void Start();
        void Stop();
         */
    }

    public class VideoSourceCommonInstancesHolder
    {
        private static VideoSourceCommonInstancesHolder _instance;
        public static VideoSourceCommonInstancesHolder SingletonInstance
        {
            get
            {
                if (_instance == null)
                    _instance = new VideoSourceCommonInstancesHolder();
                return _instance;
            }
        }

        private VideoSourceCommonInstancesHolder()
	    {
	    }

        private Dictionary<string, IVideoSourceCommon> _videoSourceDictionary = new Dictionary<string,IVideoSourceCommon>();
        public void Register(IVideoSourceCommon videoSource)
        {
            _videoSourceDictionary.Add(videoSource.Name, videoSource);
        }

        public void UnRegister(IVideoSourceCommon videoSource)
        {
            if (videoSource != null)
                _videoSourceDictionary.Remove(videoSource.Name);
        }

        public IVideoSourceCommon[] VideoSources
        {
            get
            {
                IVideoSourceCommon[] arr = new IVideoSourceCommon[_videoSourceDictionary.Count];
                _videoSourceDictionary.Values.CopyTo(arr, 0);
                return arr;
            }
        }
    }
}
